import random
import string


def add(account, name, password, position, savings):
    if len(BANK[1]) >= 100:
        return 3
    elif account in BANK[1].keys():
        return 2
    else:
        account = ''.join(random.sample(string.digits, 8))
        while account in BANK[1].keys():
            account = ''.join(random.sample(string.digits, 8))
        BANK[1][account] = {'name': name, 'password': password, 'position': position, 'savings': savings}
        print('账号为：{}'.format(account))
        return 1


def deposit(account, money):
    if account not in BANK[1].keys():
        return False
    else:
        BANK[1][account]['savings'] += money
        return True


def withdraw(account, password, money):
    if account not in BANK[1].keys():
        return 1
    elif password != BANK[1][account]['password']:
        return 2
    elif money > BANK[1][account]['savings']:
        return 3
    else:
        BANK[1][account]['savings'] -= money


def transfer(account_from, account_to, password, money):
    if (account_from not in BANK[1].keys()) | (account_to not in BANK[1].keys()):
        return 1
    elif password != BANK[1][account_from]['password']:
        return 2
    elif money > BANK[1][account_from]['savings']:
        return 3
    else:
        BANK[1][account_from]['savings'] -= money
        BANK[1][account_to]['savings'] += money
        return 0


def check(account, password):
    if account not in BANK[1].keys():
        print('用户不存在!')
    elif password != BANK[1][account]['password']:
        print('密码错误!')
    else:
        print('当前账号：{}，姓名：{}，密码:{}，余额：{}元，用户居住地址：{}{}{}{}，当前账户的开户行：{}。'.format(account,
                                                                                                        BANK[1][
                                                                                                            account][
                                                                                                            'name'],
                                                                                                        BANK[1][
                                                                                                            account][
                                                                                                            'password'],
                                                                                                        BANK[1][
                                                                                                            account][
                                                                                                            'savings'],
                                                                                                        BANK[1][
                                                                                                            account][
                                                                                                            'position'][
                                                                                                            0],
                                                                                                        BANK[1][
                                                                                                            account][
                                                                                                            'position'][
                                                                                                            1],
                                                                                                        BANK[1][
                                                                                                            account][
                                                                                                            'position'][
                                                                                                            2],
                                                                                                        BANK[1][
                                                                                                            account][
                                                                                                            'position'][
                                                                                                            3],
                                                                                                        BANK[0]))


BANK = ['中国工商银行的昌平支行', {
    '00000000': {'name': '张三', 'password': 123456, 'position': ['中国', '河南省', '人民路', '101'],
                 'savings': 10000}}]

print('★★★★★★★★★★★★★★★★★★★')
print('★ 中国工商银行账户管理系统 ★')
print('★★★★★★★★★★★★★★★★★★★')
print('★1.开户                ★')
print('★2.存钱                ★')
print('★3.取钱                ★')
print('★4.转账                ★')
print('★5.查询                ★')
print('★6.Bye！               ★')
print('★★★★★★★★★★★★★★★★★★★')
menu = input('请输入菜单选项：')
while menu != '6':
    if menu == '1':
        account0 = str(input('请输入账号：'))
        name0 = str(input('请输入姓名：'))
        password0 = int(input('请输入密码：'))
        country0 = str(input('请输入国家：'))
        province0 = str(input('请输入省份：'))
        street0 = str(input('请输入街道：'))
        number0 = str(input('请输入门牌号：'))
        savings0 = int(input('请输入存款：'))
        result = add(account0, name0, password0, [country0, province0, street0, number0], savings0)
        if result == 1:
            print('用户添加成功！')
        elif result == 2:
            print('用户已存在！')
        elif result == 3:
            print('用户库已满！')
    elif menu == '2':
        account0 = str(input('请输入账号：'))
        money0 = int(input('请输入金额：'))
        if deposit(account0, money0):
            print('存入成功！')
        else:
            print('用户不存在！')
    elif menu == '3':
        account0 = str(input('请输入账号：'))
        password0 = int(input('请输入密码：'))
        money0 = int(input('请输入金额：'))
        result = withdraw(account0, password0, money0)
        if result == 1:
            print('用户不存在！')
        elif result == 2:
            print('密码错误！')
        elif result == 3:
            print('金额不足！')
        else:
            print('取出成功！')
    elif menu == '4':
        account0 = str(input('请输入转出的账号：'))
        account1 = str(input('请输入转入的账号：'))
        password0 = int(input('请输入转出账号的密码：'))
        money0 = int(input('请输入金额：'))
        result = transfer(account0, account1, password0, money0)
        if result == 0:
            print('转账成功！')
        elif result == 1:
            print('转入或转出用户不存在！')
        elif result == 2:
            print('密码错误！')
        elif result == 3:
            print('金额不足！')
    elif menu == '5':
        account0 = str(input('请输入账号：'))
        password0 = int(input('请输入密码：'))
        check(account0, password0)
    else:
        print('没有该菜单选项！')
    menu = input('请输入菜单选项：')
